<form id="content-form" lay-filter="content-form" class="layui-form">

    <div class="layui-form-item">
        <label class="layui-form-label">标题</label>
        <div class="layui-input-block">
            <input id="title" name="title" placeholder="标题" type="text" class="layui-input" maxlength="20" lay-verify="required"/>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">标签</label>
        <div class="layui-input-block">
            <input id="tag" name="tag" placeholder="标签" type="text" class="layui-input" maxlength="20" lay-verify="required"/>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">内容</label>
        <textarea id="oriContent" name="content" placeholder="请输入内容" class="layui-textarea"></textarea>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">展示</label>
        <div class="layui-input-block" id="result">

        </div>
    </div>

    <div class="layui-form-item model-form-footer">
        <button class="layui-btn layui-btn-primary close" type="button">取消</button>
        <button class="layui-btn" lay-filter="content-form-submit" lay-submit>保存</button>
    </div>
</form>

<script type="text/javascript" src="assets/libs/marked.js"></script>
<script>
    layui.use(['layer', 'crown','form'], function () {

        var $ = layui.jquery;
        var layer = layui.layer;
        var crown = layui.crown;
        var form = layui.form;

        $('#oriContent').keyup(function(a){

            var text =  $('#oriContent').val();
            var html = marked(text);
            $('#result').html(html);
        });

        // 表单提交事件
        form.on('submit(content-form-submit)', function (data) {

            layer.load(2);

            crown.post('/content', {data: data.field}, function () {
                layer.closeAll('loading');
                layer.msg('添加成功', {icon: 1});
                crown.finishPopupCenter();
            });
            return false;
        });

    });
</script>